﻿@{
    Layout = null;
}
@model Freshbox2._0.MODEL.store
<!DOCTYPE html>

<html>
<head>
    <link rel="shortcut icon" href="favicon.ico">
    <link rel="icon" type="image/gif" href="~/img/animated_favicon1.gif">
    <meta name="viewport" content="width=device-width" />
    <link href="~/UILibs/easyui/themes/default/easyui.css" rel="stylesheet" />
    <link href="~/UILibs/easyui/themes/icon.css" rel="stylesheet" />
    <link href="~/Css/css.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.7.1.min.js"></script>
    <script src="~/UILibs/easyui/jquery.easyui.min.js"></script>
    <script src="~/UILibs/easyui/locale/easyui-lang-zh_CN.js"></script>
      <script src="~/Scripts/datagrid-detailview.js"></script>
    @*  <script src="~/Scripts/jquery.unobtrusive-ajax.min.js"></script>*@
    <script src="~/Scripts/jquery.validate.min.js"></script>
    <script src="~/Scripts/jquery.validate.unobtrusive.js"></script>
    <title></title>
    <script type="text/javascript">

        $(function () {
            $('#store').combobox({
                valueField: "shopID", //Value字段 
                textField: "shopName", //Text字段 
                multiple: true,
                url: "/Manager/GetShop", //数据源   
            });
            $("#data").datagrid({
                fit: true,
                title: '店铺信息管理',
                striped: true,
                rownumbers: true,
                columns:
                    [[{
                        field: 'ck',
                        checkbox: true
                    }, {
                        field: 'storeid',   //storeid    storeName    storeDress
                        title: '店铺编号',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        sortable: true,
                        align: 'center'
                    }, {
                        field: 'storeName',
                        title: '店铺名称',
                        width: 300,
                        height: 50,
                        halign: 'center',
                        align: 'center',

                    }, {
                        field: 'storeDress',
                        title: '店铺地址',
                        width: 300,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    }, {
                        field: 'property',
                        title: '货架型号',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        align: 'center',

                    }, {
                        field: 'discount',
                        title: '现折扣',
                        width: 150,
                        height: 50,
                        halign: 'center',
                        align: 'center'
                    },
                    //{
                    //    field: 'RealName',
                    //    title: '理货员姓名',
                    //    width: 150,
                    //    height: 50,
                    //    halign: 'center',
                    //    align: 'center'
                    //}
                    ]],
                url: pageConfig.getAction,
                pagination: true,
                pageSize: 25,
                pageList: [25, 30, 35],
                sortName: 'storeid',//storeName   
                sortOrder: 'desc',
                toolbar: '#tool',
                queryParams: {
                    storeName: $("#txtName").val().trim(),
                },
            });


            $("#formdialog").dialog({
                width: 450,
                height: 400,
                closed: true,
                modal: true,
                buttons: '#btns'
            });

        });

        var pageConfig = {
            type: null,
            getManager: '@Url.Action("GetManagerName")',
            getAction: '@Url.Action("Get")',//GetAll
            saveAction: '@Url.Action("Save2Wares")',
            delAction: '@Url.Action("ModifyState")',
            modifyAction: '@Url.Action("Modify2")',
            getOneAction: '@Url.Action("GetOnlyOne")',
        };

        ///删除店铺信息  其实是状态的改变  
        function del() {

            var rows = $("#data").datagrid("getSelections")
            if (rows.length <= 0) {
                $.messager.alert("删除店铺信息", "没有选中的行", "info");
                return;
            }
            $.messager.confirm("确定操作", "您确定要删除该店铺吗？", function (flag) {
                if (flag) {
                    var idsStr = rows[0].storeid;
                    $.ajax({
                        url: pageConfig.delAction,
                        data: { id: idsStr },
                        dataType: "json",
                        type: "POST",
                        beforeSend: function () {
                            before();
                        },
                        success: function (data) {
                            success(data);
                        },
                        error: function () {
                            error();
                        },
                        complete: function () {
                            complete();
                        }
                    });
                }
            })
        }

        //弹出框
        function alertFormDialog(type) {
            //动态加载  店铺列表 
            $("#manager").combobox({
                url: pageConfig.getManager,
                //action 
                valueField: "UserID",
                textField: "UserName"
            });
            pageConfig.type = type;
            $("#formdialog form").form("reset");
            if (type == 1) {
                $("#formdialog").dialog("open");
                $("#formdialog").dialog("setTitle", "添加店铺");
                $("#formdialog form").attr("action", pageConfig.saveAction);

            }
            else {
                var rows = $("#data").datagrid("getSelections");
                if (rows.length != 1) {
                    $.messager.alert("提示", "修改时必须且只能选中一条记录！", "info");
                    return;  //返回  不往下执行
                }
                $("#formdialog").dialog("open");
                $("#formdialog").dialog("setTitle", "修改店铺信息");
                //$('#adminUsername').attr("disabled", true);//不可编辑
                $.ajax({
                    async: false,
                    url: pageConfig.getOneAction + "?id=" + rows[0].storeid,
                    dataType: "json",
                    type: "POST",
                    success: function (data) {
                        $("#storeid").val(data.storeid);
                        $("#storeName").val(data.storeName);
                        $("#discount").val(data.discount);
                        $("#storeDress").val(data.storeDress);
                        $("#property").combobox('setValue', data.property);
                       // $("#manager").combobox('setValue', data.userid);
                    }
                });
            }
        };

        function closeDptDialog() {
            $("#formdialog").dialog("close")
        }
        //点击保存按钮 
        function save() {
            //storeid    storeName    storeDress
            //var a = $("#storeid").val();
            //if ($("#storeName").val() != null && $("#storeName").val() != "" && $("#storeDress").val() != null && $("#storeDress").val() != "") {
                var bool = $("#fm").form("validate");
                if (bool) {
                    var rows = $("#data").datagrid("getSelections");
                    var data;
                    if (pageConfig.type == 1) {
                        url = pageConfig.saveAction;
                        data = {
                            storeName: $("#storeName").val(),
                            storeDress: $("#storeDress").val(),
                          //  managerCode: $("#manager").combobox('getValue'),
                            property: $("#property").combobox('getValue'),
                            discount: $("#discount").val(),
                        };
                    }
                    else {
                        url = pageConfig.modifyAction;
                        data = {
                            storeid: $("#storeid").val(),
                            storeName: $("#storeName").val(),
                            storeDress: $("#storeDress").val(),
                          //  managerCode: $("#manager").combobox('getValue'),
                            property: $("#property").combobox('getValue'),
                            discount: $("#discount").val(),

                        };
                    }
                    $.ajax({
                        url: url,
                        dataType: "json",
                        data: data,
                        type: "POST",
                        beforeSend: function () {
                            $.messager.progress({ title: "执行中", text: "" });
                        },
                        success: function (data) {
                            $.messager.alert("成功", data.msg, "info");
                        },
                        error: function (data) {
                            $.messager.alert("警告", "系统故障", "error", "")
                        },
                        complete: function () {

                            complete();
                        }
                    });
                }
            //}
            //else {
            //    $.messager.alert("提示", "请把信息填写完整", "info");
            //}
        }

        //搜索查询  oninput 是 每一个字符都要查
        function searchData() {
            $("#data").datagrid('load', {
                storeName: $("#txtName").val()

            });
        }

        function before() {
            $.messager.progress({ title: "执行中", text: "" });
        }
        function success(data) {
            $.messager.alert("成功", data.msg, "info");
        }
        function error() {
            $.messager.alert("警告", "系统故障", "error", "")
        }
        function complete() {
            $("#data").datagrid("load");
            $.messager.progress("close");
            $("#formdialog").dialog("close");
        }
    </script>
</head>
<body class="easyui-layout" style="width: 100%; height: 100%">
    <div data-options="region:'center'">
        <table id="data"></table>
        <div id="tool" style="padding: 10px;">
            <div style="margin-bottom: 10px;">
                <div style="margin-bottom: 10px;">
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp  店铺名称： &nbsp&nbsp<input id="txtName" type="text" onchange="searchData()" style="width: 200px; height: 20px;" />
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                <a class="easyui-linkbutton" style="width: 100px; height: 50px;" iconcls="icon-search" onclick="searchData()">查询</a>
                    &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" style="width: 100px; height: 50px;" iconcls="icon-add" onclick="alertFormDialog(1)">新增店铺</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" style="width: 150px; height: 50px;" iconcls="icon-edit" onclick="alertFormDialog(2)">修改店铺/优惠 信息</a> &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp 
                    <a class="easyui-linkbutton" style="width: 150px; height: 50px;" iconcls="icon-remove" onclick="del()">删除店铺信息</a>
                    <div style="margin-top: 20px;">
                        <span style="font-size: larger; color: red">&nbsp&nbsp &nbsp&nbsp&nbsp   &nbsp&nbsp&nbsp &nbsp&nbsp&nbsp   注意:新增店铺时，根据货架型号和对应的商品模板，自动添加商品</span>
                        <br />

                    </div>

                </div>
            </div>
        </div>
    </div>

    <div id="formdialog">
        @using (Ajax.BeginForm(new AjaxOptions
        {
            OnBegin = "before",
            OnComplete = "complete",
            OnSuccess = "success",
            OnFailure = "error",
            HttpMethod = "Post"
        }))
        {
            <div class="dialog-table">
                <form id="fm" method="post">
                    @Html.HiddenFor(x => x.storeid)
                    <table width="100%" border="0" cellspacing="0" cellpadding="0" class="tk_table">
                        <tr hidden="hidden">
                            <td>店铺id：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="storeid" /></td>
                        </tr>
                        <tr>
                            <td>店铺名称：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" id="storeName" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>店铺地址：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" type="text" id="storeDress" data-options="required:true" /></td>
                        </tr>
                        <tr>
                            <td>折扣：</td>
                            <td class="white-tr">
                                <input class="easyui-validatebox" type="text" id="discount" data-options="required:true" />
                                不打折为1，打折请填写小数
                            </td>

                        </tr>
@*                        <tr>
                            <td>指派理货员：</td>
                            <td class="white-tr">
                                <input class="easyui-combobox" id="manager" name="manager" data-options="required:true" /></td>
                        </tr>*@
                        <tr>
                            <td>货架型号：</td>
                            <td class="white-tr">
                                <select class="easyui-combobox" id="property" name="property" style="width: 100px">
                                    <option value="1">大号</option>
                                    <option value="2">结算台+冰箱</option>
                                    <option value="4">结算台+货架</option>
                                    <option value="3">小号</option>
                                    <option value="5">货架+冰箱</option>
                                </select>
                        </tr>
                    </table>
                </form>
            </div>
        }
    </div>

    <div id="btns">
        <div style="margin-bottom: 10px">
            <a class="easyui-linkbutton" iconcls="icon-redo" onclick="closeDptDialog()">取消</a>
            <a class="easyui-linkbutton" iconcls="icon-add" onclick="save()">保存</a>
        </div>
    </div>

</body>
</html>
